<?php

namespace App\Models\User;

use App\Libraries\Easemob\Easemob;
use App\Libraries\Tools\URL;
use App\Models\BaseModel;

class SMS extends BaseModel
{

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'mobile',
        'code',
        'status',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'created_at',
        'updated_at',
    ];

    protected $table = 'sms_code';
    protected $dateFormat = 'U';


    /**
     * 返回符合条件的验证码记录
     * @param $mobile
     * @param $code
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function checkCode($mobile, $code){
        $time = time();
        $data = $this->where('mobile', $mobile)
            ->where('code', $code)
            ->where('status', 0)
            ->where('created_at', '>=', $time-600)
            ->orderBy('id', 'desc')
            ->first();
        return $data;
    }
}
